#!/bin/sh
# Simple test of dxdiag commandline handling

# Let user override location of wine, but default to just plain 'wine'
WINE=${WINE:-wine}

# Function to run Windows command but with parent directory as first item in PATH
# so we pick up the dxdiag.exe we built 
# To run with native dxdiag, do 'winetricks-alpha dxdiag' but delete the dxdiag.exe we built
run()
{
    cat > run.bat <<_EOF_
PATH ..;%PATH%
$1 $2
_EOF_
    $WINE cmd /c run.bat
}

# Check behavior with just one option
# Usage:
#  check_one_opt option expected_outfile nonexpected_outfile
check_one_opt()
{
    echo "Running 'dxdiag $1', expecting output file $2, not expected output file $3"
    rm -f "$2" "$3"
    run dxdiag.exe $1 > dxdiag_out.log 2>&1
    if ! test -f "$2"
    then
        echo "Expected output file $2, but didn't see it."
        exit 1
    fi
    if test -f "$3"
    then
        echo "Did not expect output file $3, but saw it."
        exit 1
    fi
}

check_one_opt -t dxdiag.txt dxdiag.xml
check_one_opt -T dxdiag.txt dxdiag.xml
check_one_opt /t dxdiag.txt dxdiag.xml
check_one_opt /T dxdiag.txt dxdiag.xml
check_one_opt -x dxdiag.xml dxdiag.txt
check_one_opt -X dxdiag.xml dxdiag.txt
check_one_opt /x dxdiag.xml dxdiag.txt
check_one_opt /X dxdiag.xml dxdiag.txt
check_one_opt /X dxdiag.xml dxdiag.txt
